package view.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import model.HostAddress;
import model.IPAddress;
import view.dialogs.MultiInfoDialog;
import controller.Controller;

public class MultiInfoListener implements ActionListener {

	private final MultiInfoDialog multiInfoDialog;

	public MultiInfoListener(MultiInfoDialog multiInfoDialog) {
		this.multiInfoDialog = multiInfoDialog;
	}

	@Override
	public void actionPerformed(ActionEvent e) {

		int i = 0;
		ArrayList<HostAddress> hostList = Controller.getInstance().getHosts();
		int hostIndex = Controller.getInstance().getIndexHost();
		int subIndex = Controller.getInstance().getIndexSub();
		for (IPAddress element : Controller.getInstance().getMultiIpList()) {
			int indexIp = hostList.get(hostIndex).getSubnetList().get(subIndex)
					.getIpAddressList().indexOf(element);
			hostList.get(hostIndex)
					.getSubnetList()
					.get(subIndex)
					.getIpAddressList()
					.get(indexIp)
					.setAdditionalInfo(
							Controller.getInstance().getIpInfoList()
					.get(i).getText());
			i++;

		}
		Controller.getInstance().setHosts(hostList);
		multiInfoDialog.dispose();
	}

}
